package com.mcp_life.module.mcpclientmodules.repository;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class InMemoryChatHistoryRepository implements ChatHistoryRepository{
    private final Map<String, List<String>> chatHistory=new HashMap<>();
    @Override
    public void save(String type, String chatId) {
        log.info("开始保存会话信息，{}",type);
        if (!chatHistory.containsKey(type)){
            chatHistory.put(type,new ArrayList<>());
        }
        List<String> chatIds = chatHistory.get(type);
        if (chatIds.contains(chatId)){
            log.info("会话信息已存在，{}",type);
            return ;
        }
        log.info("保存会话信息，{}",type);
        chatIds.add(chatId);
    }
    @Override
    public List<String> getChatId(String type) {

        List<String> chatId = chatHistory.get(type);
        return chatId==null?new ArrayList<>():chatId;
    }
}
